/* eslint-disable */
// @ts-ignore
import { queryOptions, useMutation } from '@tanstack/vue-query';
import type { DefaultError } from '@tanstack/vue-query';
import request from '@/utils/request';
import { CustomRequestOptions } from '@/interceptors/request';

import * as apis from './weixinzhifu';
import * as API from './types';

/** 关闭订单 POST /tourism/client/c/wxpay/closeOrder */
export function useCloseOrderUsingPostMutation(options?: {
  onSuccess?: (value?: API.CommonResultString_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.closeOrderUsingPost,
    onSuccess(data: API.CommonResultString_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 创建支付订单 POST /tourism/client/c/wxpay/createOrder */
export function useCreateOrderUsingPostMutation(options?: {
  onSuccess?: (value?: API.CommonResultMapStringObject_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.createOrderUsingPost,
    onSuccess(data: API.CommonResultMapStringObject_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 获取小程序支付参数 GET /tourism/client/c/wxpay/getPayParams */
export function getPayParamsUsingGetQueryOptions(options: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.getPayParamsUsingGETParams;
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.getPayParamsUsingGet(queryKey[1] as typeof options);
    },
    queryKey: ['getPayParamsUsingGet', options],
  });
}

/** 支付结果通知V3 POST /tourism/client/c/wxpay/notifyV3 */
export function useHandlePayNotifyV3UsingPostMutation(options?: {
  onSuccess?: (value?: string) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.handlePayNotifyV3UsingPost,
    onSuccess(data: string) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 查询订单支付状态 GET /tourism/client/c/wxpay/queryOrderStatus */
export function queryOrderStatusUsingGetQueryOptions(options: {
  // 叠加生成的Param类型 (非body参数openapi默认没有生成对象)
  params: API.queryOrderStatusUsingGETParams;
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.queryOrderStatusUsingGet(queryKey[1] as typeof options);
    },
    queryKey: ['queryOrderStatusUsingGet', options],
  });
}

/** 申请退款 POST /tourism/client/c/wxpay/refund */
export function useRefundUsingPostMutation(options?: {
  onSuccess?: (value?: API.CommonResultString_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.refundUsingPost,
    onSuccess(data: API.CommonResultString_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}

/** 测试微信支付V3接口 专门用于测试微信支付V3接口连通性 GET /tourism/client/c/wxpay/testV3Api */
export function testV3ApiUsingGetQueryOptions(options: {
  options?: CustomRequestOptions;
}) {
  return queryOptions({
    queryFn: async ({ queryKey }) => {
      return apis.testV3ApiUsingGet(queryKey[1] as typeof options);
    },
    queryKey: ['testV3ApiUsingGet', options],
  });
}

/** 验证微信支付配置 用于检查微信支付配置是否有效 POST /tourism/client/c/wxpay/validateConfig */
export function useValidateConfigUsingPostMutation(options?: {
  onSuccess?: (value?: API.CommonResultMapStringObject_) => void;
  onError?: (error?: DefaultError) => void;
}) {
  const { onSuccess, onError } = options || {};

  const response = useMutation({
    mutationFn: apis.validateConfigUsingPost,
    onSuccess(data: API.CommonResultMapStringObject_) {
      onSuccess?.(data);
    },
    onError(error) {
      onError?.(error);
    },
  });

  return response;
}
